/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * VentanaIngresoTaos.java
 *
 * Created on 03-jun-2012, 21:22:06
 */
package View;

import Controller.MainController;
import Model.twoWays;
import java.util.ArrayList;
import javax.swing.JOptionPane;

/**
 *
 * @author r4wd3r
 */
public class VentanaIngresoTaos extends javax.swing.JFrame {

    /** Creates new form VentanaIngresoTaos */
    public VentanaIngresoTaos() {
        initComponents();
        setRandomValues();       
    }
    
    private void setRandomValues(){
        String defectTaos = null, defectBetas = null;
        ArrayList<Double> array = new ArrayList<Double>();
        array = twoWays.getListaBetas();
        for (Double d : twoWays.getListaBetas()) {
            System.out.println("Betas: "+d);
            if(defectBetas == null){
                defectBetas = d.toString();
            }
            else{
                defectBetas += d.toString();      
            }
            defectBetas += ",";
        }
        
        for (Double d : twoWays.getListaTaos()) {
            if(defectTaos == null){
                defectTaos = d.toString();
            }
            else{
                defectTaos += d.toString();               
            }
            defectTaos+= ",";
        }
        System.out.println(defectTaos);
        System.out.println(defectBetas);
        System.out.println("Cantidad de Taos: " + twoWays.getListaTaos().size());
        System.out.println("Cantidad de Betas: " + twoWays.getListaBetas().size());
        TaosTextField.setText(defectTaos);
        BetasTextField.setText(defectBetas);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        TaosTextField = new javax.swing.JTextField();
        BetasTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        GuardarBoton = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        TaosTextField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                TaosTextFieldActionPerformed(evt);
            }
        });

        jLabel1.setText("Taos:");

        jLabel2.setText("Betas:");

        GuardarBoton.setText("Guardar");
        GuardarBoton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                GuardarBotonActionPerformed(evt);
            }
        });

        jLabel3.setText("Ingrese los datos respectivos a cada fila y columna separados por una coma.");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(314, Short.MAX_VALUE)
                .addComponent(GuardarBoton)
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(BetasTextField)
                            .addComponent(TaosTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE))))
                .addContainerGap(16, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jLabel3)
                .addGap(36, 36, 36)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TaosTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BetasTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(18, 18, 18)
                .addComponent(GuardarBoton)
                .addContainerGap(21, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void TaosTextFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TaosTextFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_TaosTextFieldActionPerformed

    private void GuardarBotonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GuardarBotonActionPerformed
        String taos,betas;
        taos = TaosTextField.getText();
        betas = BetasTextField.getText();
        //Aqui van las reglas de validacion//
        if(MainController.validarTaosYBetas(taos, betas)){
            JOptionPane.showMessageDialog(null, "Datos Guardados", "Alerta", JOptionPane.INFORMATION_MESSAGE);
        }
        else{
            JOptionPane.showMessageDialog(null, "Existen errores en los campos", "Alerta", JOptionPane.INFORMATION_MESSAGE);
        }
        
    }//GEN-LAST:event_GuardarBotonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VentanaIngresoTaos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VentanaIngresoTaos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VentanaIngresoTaos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VentanaIngresoTaos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new VentanaIngresoTaos().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField BetasTextField;
    private javax.swing.JButton GuardarBoton;
    private javax.swing.JTextField TaosTextField;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}
